package com.example.demo.model;

import com.example.demo.enums.ResultStatus;
import lombok.Data;

@Data
public class Result<T> {
    private ResultStatus stauts;
    private String errorMessage;
    private T data;


    /*
    * 返回成功
    */
    public static <T>Result success(T data){
        Result result=new Result();
        result.setStauts(ResultStatus.SUCCESS);
        //信息已经包含在data中
        result.setErrorMessage("");
        result.setData(data);
        return result;
    }

    public static Result fail(String msg){
        Result result=new Result();
        result.setStauts(ResultStatus.FAIL);
        result.setErrorMessage(msg);
        result.setData("");
        return result;
    }

    public static Result unlogin(){
        Result result=new Result();
        result.setStauts(ResultStatus.UNLOGIN);
        result.setErrorMessage("用户未登入");
        result.setData("");
        return result;
    }

}
